home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / xdisplay.c < prev   
C/C++ Source or Header  |  1993-05-14  |  24KB  |  915 lines

  1.  
  2.  
  3.    /**************************************************
  4.    *
  5.    *   file d:\cips\display.c
  6.    *
  7.    *   Functions: This file contains
  8.    *      display_image
  9.    *      display_image_portion
  10.    *      display_menu_for_display_image
  11.    *      map_16_shades_of_gray
  12.    *      map_64_shades_of_gray
  13.    *      transform_the_colors
  14.    *
  15.    *   Purpose:
  16.    *      These functions display images on a the
  17.    *      monitor.
  18.    *
  19.    *   External Calls:
  20.    *      rtiff.c - read_tiff_image
  21.    *      cips.c - my_clear_text_screen
  22.    *      hist.c - zero_histogram
  23.    *               calculate_histogram
  24.    *               perform_histogram_equalization
  25.    *               display_histogram
  26.    *
  27.    *   Modifications:
  28.    *      17 June 1987 - created
  29.    *      August 1990 - extension modifications for use
  30.    *          in the C Image Processing System.
  31.    *
  32.    ***************************************************/
  33.  
  34.  
  35. #include "cips.h"
  36.  
  37.  
  38.  
  39.  
  40.  
  41.    /***************************
  42.    *
  43.    *   display_image(...
  44.    *
  45.    ****************************/
  46.  
  47.  
  48. display_image(file_name, image, il, ie, ll, le,
  49.               image_header, monitor_type, 
  50.               color_transform, invert, image_colors, 
  51.               display_colors, show_hist, title)
  52.    char    color_transform[],
  53.            file_name[],
  54.            monitor_type[],
  55.            title[];
  56.    int     display_colors,
  57.            image_colors,
  58.            invert,
  59.            il,
  60.            ie,
  61.            ll,
  62.            le,
  63.            show_hist;
  64.    short   image[ROWS][COLS];
  65.    struct  tiff_header_struct *image_header;
  66. {
  67.    char  channels[80],
  68.          response[80];
  69.  
  70.    int   a,
  71.          b,
  72.          c,
  73.          channel,
  74.          count,
  75.          display_mode,
  76.          dx_offset,
  77.          dy_offset,
  78.          key,
  79.          horizontal,
  80.          len,
  81.          max_horizontal,
  82.          max_vertical,
  83.          not_finished,
  84.          q,
  85.          r,
  86.          vertical,
  87.          x_offset,
  88.          y_offset;
  89.  
  90.    unsigned int block,
  91.                 color,
  92.                 i,
  93.                 j,
  94.                 x,
  95.                 y;
  96.    unsigned long histogram[256], new_hist[256];
  97.  
  98.  
  99.      /**********************************************
  100.      *
  101.      *   If you want to display the histogram and 
  102.      *   do not want to perform hist equalization, 
  103.      *   then zero the histogram for calculations.
  104.      *
  105.      **********************************************/
  106.  
  107.    if(  (show_hist == 1)   &&
  108.         (color_transform[0] != 'H'))
  109.       zero_histogram(histogram);
  110.  
  111.    not_finished = 1;
  112.    while(not_finished){
  113.  
  114.  
  115.       if(display_colors == 16){
  116.          if(monitor_type[0] == 'V'){
  117.             horizontal   = 4;
  118.         vertical = 6;
  119.         display_mode = _VRES16COLOR; /* MSC 6.0 */
  120.          }  /* ends if V */
  121.          if(monitor_type[0] == 'E'){
  122.             horizontal   = 3;
  123.             vertical     = 6;
  124.             display_mode = _ERESCOLOR; /* MSC 6.0 */
  125.          }  /* ends if E */
  126.  
  127.       }  /* ends if colors == 16 */
  128.  
  129.       else{
  130.          horizontal   = 2;
  131.          vertical     = 2;
  132.          display_mode = _MAXCOLORMODE; /* MSC 6.0 */
  133.       }
  134.  
  135.         /********************************************
  136.         *
  137.         *   Somehow, my dx and dy offsets are 
  138.         *   backwards from my horizontal and vertical 
  139.         *   variables. Trying to center the images 
  140.         *   on the screen. March 21 1992
  141.         *
  142.         ********************************************/
  143.  
  144.       max_horizontal = (image_header->image_length+50)
  145.                        /COLS;
  146.       max_vertical   = (image_header->image_width+50)
  147.                        /ROWS;
  148.  
  149.       dy_offset = ((horizontal-max_horizontal)/2)
  150.                   *COLS + 50;
  151.       dx_offset = ((vertical-max_vertical)/2)
  152.                   *ROWS + 20;
  153.  
  154.       if(max_horizontal > horizontal) dy_offset = 0;
  155.       if(max_vertical > vertical)     dx_offset = 0;
  156.  
  157.       if(horizontal > max_horizontal) 
  158.          horizontal = max_horizontal;
  159.       if(vertical > max_vertical)     
  160.          vertical   = max_vertical;
  161.  
  162.  
  163.         /****************************************
  164.         *
  165.         *   If color transform wants histogram
  166.         *   equalization, then read in the
  167.         *   image arrays and calculate the
  168.         *   histogram.   Zero both the histogram
  169.         *   and the new_hist.  You will need the
  170.         *   new_hist if you want to display the
  171.         *   equalized hist.
  172.         *
  173.         *****************************************/
  174.  
  175.       if(color_transform[0] == 'H'){
  176.          count = 1;
  177.          zero_histogram(histogram);
  178.          zero_histogram(new_hist);
  179.          for(a=0; a<vertical; a++){
  180.             for(b=0; b<horizontal; b++){
  181.  
  182.                x = a*COLS;
  183.                y = b*ROWS;
  184.  
  185.                printf(
  186.                   "\nDISPLAY> Calculating histogram");
  187.                printf(" %d of %d",
  188.                   count,vertical*horizontal);
  189.                count++;
  190.                read_tiff_image(file_name, image, il+y,
  191.                             ie+x, ll+y, le+x);
  192.                calculate_histogram(image, histogram);
  193.  
  194.             }  /* ends loop over b */
  195.          }  /* ends loop over a */
  196.       }  /* ends if display_mode == H */
  197.  
  198.  
  199.         /* set graphics mode */
  200.  
  201.    _setvideomode(display_mode); /* MSC 6.0 */
  202.    if(display_colors == 16) 
  203.       map_16_shades_of_gray(display_mode);
  204.    if(display_colors == 256) 
  205.       map_64_shades_of_gray();
  206.  
  207.  
  208.         /****************************************
  209.         *
  210.         *   Loop over this size and
  211.         *   read and display ROWSxCOLS arrays.
  212.         *
  213.         *   If you want to show the histogram AND
  214.         *   do not want to do hist equalization
  215.         *   then calculate the hist from the
  216.         *   original image array.
  217.         *
  218.         *   If you want to do hist equalization
  219.         *   then calculate the new_hist AFTER
  220.         *   the image has been equalized by the
  221.         *   the transform_the_colors function.
  222.         *
  223.         *   NOTE: Remember that the function
  224.         *   transform_the_colors changes the
  225.         *   gray shade values in image array.
  226.         *
  227.         *****************************************/
  228.  
  229.         /*****************************************
  230.         *
  231.         *   These statements place a gray 
  232.         *   background across the display area of 
  233.         *   a VGA screen.  This reduces the 
  234.         *   contrast between the screen background 
  235.         *   and the images you display. This makes 
  236.         *   it easier to take photos.
  237.         *
  238.         *******************************************/
  239.  
  240.       _setlinestyle(0xFFFF);
  241.       _setcolor(10);
  242.       for(i=0; i<640;i++){
  243.          _moveto(i, 0);
  244.          _lineto(i, 480);
  245.       }
  246.  
  247.       for(a=0; a<vertical; a++){
  248.          for(b=0; b<horizontal; b++){
  249.  
  250.             x = a*COLS;
  251.             y = b*ROWS;
  252.             read_tiff_image(file_name, image, il+y,
  253.                             ie+x, ll+y, le+x);
  254.             if(  (show_hist == 1)  &&
  255.                  (color_transform[0] != 'H'))
  256.                calculate_histogram(image, histogram);
  257.  
  258.             transform_the_colors(image, 
  259.                                  color_transform,
  260.                                  display_colors,
  261.                                  image_colors, 
  262.                                  histogram,
  263.                                  horizontal, 
  264.                                  vertical);
  265.  
  266.             if(color_transform[0] == 'H')
  267.                calculate_histogram(image, new_hist);
  268.           display_image_portion(image, x+dx_offset,
  269.                                 y+dy_offset, 
  270.                                 display_colors,
  271.                                 image_colors, invert);
  272.          }        /* ends loop over b */
  273.       }        /* ends loop over a */
  274.  
  275.           /*******************************************
  276.           *
  277.           *   Put in these statements to print a title 
  278.           *   at the bottom of the display.  This is 
  279.           *   nice for taking photos or articles 
  280.